<script language="javascript" type="text/javascript">
    function getCategoryType(obj){
        $.ajax({
            url: AJAX_PROCESS_URL+'getCategoryType',
            type: 'POST',
            data: "type=" + obj.value,
            error: function(){
                alert('Connection error!');
            },
            success: function(data){
                $("select[name=cat_id]").html(data);
            }
        });
    }
    function check_email(email) {



        var filter = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;


        if(!filter.test(email)){

            return false

        }
        return true;

    }
    function newsLetter(email){

        if(check_email(email))
        {
            $('#newsLetter').attr('border-color', 'black', 'style');
            $.ajax({
                url: AJAX_PROCESS_URL+'newsLetter',
                type: 'POST',
                data: "email=" + email,
                error: function(){
                    alert('Connection error!');
                },
                success: function(){
                    alert('Cảm ơn bạn đã đăng ký nhận thư!');
                }
            });
        }else
        {


            $('#newsLetter').attr('border-color', 'red', 'style');
            $('#newsLetter').val('');
            $('#newsLetter').focus();
            $("#lblThongBao").attr('visibility', 'visible', 'style');
        }
    }
    function getGeo(obj,forObj){
        if(obj.value>0){
            $.ajax({
                url: AJAX_PROCESS_URL+'getDistrict',
                type: 'POST',
                data: "city=" + obj.value,
                error: function(){
                    alert('Error!');
                },
                success: function(data){
                    if(forObj=='city'){
                        $("select[name=geo_id[0]]").html(data);
                        $("select[name=geo_id[1]]").html('<option value="0">Select geographic...</option>');
                    }else if(forObj=='district'){
                        $("select[name=district]").html(data);
                    }

                }
            });
        }else{
            $("select[name=geo_id[1]]").html('<option value="0">Select geographic...</option>');
        }
    }
    function search (){
        $('#frmSearch').submit();
    }
</script>
<div class="main_left">

    <div class="title_search" style="background: url('/images/title_search.gif') no-repeat;"><span></span></div>
    <div class="box_body">
        <form action="<?php echo get_link('property');?>/" id="frmSearch" method="get">
            <div class="linesearch">
                <ul>
                    <li>
                        <div class="linesearh_left">[Loại hình]:</div>
                        <div class="linesearh_right">
                            <select name="type" onchange="getCategoryType(this);">
                                <option value="0">[Chọn loại tin]</option>
                                <?php
                                if($_REQUEST['type']==2) {
                                    echo '<option value="1">[Cần bán]</option>';
                                    echo '<option selected="selected" value="2">[Cho thuê]</option>';
                                }elseif($_REQUEST['type']==1) {

                                    echo '<option selected="selected" value="1">[Cần bán]</option>';
                                    echo '<option value="2">[Cho thuê]</option>';
                                }else {
                                    echo '<option value="1">[Cần bán]</option>';
                                    echo '<option value="2">[Cho thuê]</option>';
                                }
                                ?>
                            </select>
                        </div>
                    </li>
                    <li>
                        <div class="linesearh_left">[Danh mục]:</div>
                        <div class="linesearh_right">
                            <select name="cat_id">
                                <?php
                                if(intval($_REQUEST['type'])==0) {
                                    $type = 1;
                                }else {
                                    $type = intval($_REQUEST['type']);
                                }
                                $arrCatId = listPropertyCategoryByParent($type);
                                echo '<option value="0">[Chọn loại địa ốc]</option>';
                                for($i=0;$i<count($arrCatId);$i++) {
                                    echo '<option '.setSelectedBoxValue($_REQUEST['cat_id'], $arrCatId[$i]['cat_id']).' value="'.$arrCatId[$i]['cat_id'].'">'.$arrCatId[$i]['cat_title'].'</option>';
                                }

                                ?>
                            </select>
                        </div>
                    </li>
                    <li><div class="linesearh_left">[Tỉnh/TP]:</div>
                        <div class="linesearh_right">
                            <select name="city" onchange="getGeo(this,'district')">
                                <option value="0">[Tỉnh/Thành phố]</option>
                                <?php
                                $rsCity = getAllCity();
                                while ($row = $db->fetch_array($rsCity)) {
                                    if($_REQUEST['city']==$row['geo_id']) {
                                        echo '<option selected="selected" value="'.$row['geo_id'].'">'.$row['geo_title'].'</option>';
                                    }else {
                                        echo '<option value="'.$row['geo_id'].'">'.$row['geo_title'].'</option>';
                                    }
                                }
                                ?>
                            </select>
                        </div>
                    </li>
                    <li><div class="linesearh_left">[Quận huyện]:</div>
                        <div class="linesearh_right">
                            <select name="district">
                                <option value="0">[Quận/Huyện]</option>
                                <?php
                                if(isset ($_REQUEST['city']) && intval($_REQUEST['city'])>0) {
                                    $rsDistrict = getDistrictByCityId(intval($_REQUEST['city']));
                                    while ($row = $db->fetch_array($rsDistrict)) {
                                        if($_REQUEST['district']==$row['geo_id']) {
                                            echo '<option selected="selected" value="'.$row['geo_id'].'">'.$row['geo_title'].'</option>';
                                        }else {
                                            echo '<option value="'.$row['geo_id'].'">'.$row['geo_title'].'</option>';
                                        }
                                    }
                                }
                                ?>
                            </select>
                        </div>
                    </li>
                    <li><div class="linesearh_left">[Giá (VNĐ)]:</div>
                        <div class="linesearh_right">
                            <select name="price_home">
                                <option value="0">[Chọn giá]</option>
                                <option <?php setSelectedBoxValue($_REQUEST['price_home'], 'p500');?> value="p500"><500 [Triệu]</option>
                                <option <?php setSelectedBoxValue($_REQUEST['price_home'], 'p500-1');?> value="p500-1">500 [Triệu] - 1 [Tỷ]</option>
                                <option <?php setSelectedBoxValue($_REQUEST['price_home'], 'p1-3');?> value="p1-3">1 [Tỷ] - 3 [Tỷ]</option>
                                <option <?php setSelectedBoxValue($_REQUEST['price_home'], 'p3-5');?> value="p3-5">3 [Tỷ] - 5 [Tỷ]</option>
                                <option <?php setSelectedBoxValue($_REQUEST['price_home'], 'p5');?> value="p5">[Lớn hơn] 5 [Tỷ]</option>
                                <option <?php setSelectedBoxValue($_REQUEST['price_home'], 'noPrice');?> value="noPrice">[Chưa có giá]</option>
                            </select>
                        </div>
                    </li>
                    <li><div class="linesearh_left">[Diện tích]:</div>

                        <div class="linesearh_right"><select name="area" >
                                <option value="0">[Chọn diện tích]</option>
                                <option <?php setSelectedBoxValue($_REQUEST['area'], 'a50');?> value="a50">< 50m2</option>
                                <option <?php setSelectedBoxValue($_REQUEST['area'], 'a50-100');?> value="a50-100">50m2 -> 100m2</option>
                                <option <?php setSelectedBoxValue($_REQUEST['area'], 'a101-200');?> value="a101-200">101m2 -> 200m2</option>
                                <option <?php setSelectedBoxValue($_REQUEST['area'], 'a201');?> value="a201">> 200m2</option>
                            </select></div>

                    </li>
                    <li><div class="linesearh_left">[Hướng]:</div>
                        <div class="linesearh_right">
                            <select name="direction" style="width:99%;">
                                <?php
                                foreach ($CONFIG['direction'] as $key => $value) {
                                    if(isset($_REQUEST['direction']) && $_REQUEST['direction']==$key) {
                                        echo '<option selected="selected" value="'.$key.'">'.$value.'</option>';
                                    }else {
                                        echo '<option value="'.$key.'">'.$value.'</option>';
                                    }
                                }
                                ?>
                            </select>
                        </div>
                    </li>
                    <li><div class="linesearh_left">[Từ khóa]:</div>
                        <div class="linesearh_right"><input type="text" name="keyword" value="<?php if(isset($_REQUEST['keyword'])) {
                                echo $_REQUEST['keyword'];
                            }else {
                                echo '[Tìm kiếm BĐS]';
                                                            }?>" onkeydown="if (event.keyCode == 13){search();return false;}" onclick="if(this.value=='[Tìm kiếm BĐS]'){this.value=''}" onblur="if(this.value=='' || this.value==' '){this.value='[Tìm kiếm BĐS]'}" style="width:95%;" />
                        </div>
                    </li>

                </ul>
                <div onclick="$('#frmSearch').submit();" class="btn_search" style="background-image:url('/images/icon_search.gif');"></div>
            </div>
        </form>
    </div>
    <div class="box_bottom"><span></span></div>
<div style="float:left;width:100%">
    <div class="folder" >
        <div class="folder-title-new00" >
            <div class="square00"></div>
            <div style="margin-top: 7px;float: left;color: #000">[Đăng ký nhận tin]</div>
        </div>
        <div class="folder-body00" >
            <div >
                <div style=" padding-top: 10px;padding-bottom: 9px ; text-align: center; color: Red;">
                    <input id="newsLetter" type="text" style="width: 175px; color: rgb(0, 0, 0);" onkeypress="$('#lblThongBao').attr('visibility', 'hidden', 'style');" onkeydown="if (event.keyCode == 13){newsLetter(this)();return false;}" onclick="if(this.value=='[Nhập email của bạn]!'){this.value=''}" onblur="if(this.value=='' || this.value==' '){this.value='[Nhập email của bạn]!'}" value="[Nhập email của bạn]!" name="ctlHoTro_NhanEmail1$txtEmail">
                    <span id="lblThongBao" style="color: Red; visibility: hidden;" >[Email chưa đúng định dạng]!</span>
                </div>
                <div style="padding: 0px 15px; text-align: right; color: Red;">

                    <input type="image" onclick="newsLetter($('#newsLetter').val())" style="border-width: 0px;" src="images/icon_dangky.gif" >
                </div>
                <div style="padding: 0px 10px; text-align: left; color: Red;">


                </div>

            </div>


        </div>
        <div class="folder-bottom00">
            <div class="square-bottom00"></div>
        </div>
    </div>

    <div class="folder" >
        <div class="folder-title-new00" >
            <div class="square00"></div>
            <div style="float: left;color: #000">[Đối tác]</div>
        </div>
        <div class="folder-body00" style="height:260px">
            <div style="margin-bottom: 2px;">
                <marquee style="text-align: center;" scrollamount="2" scrolldelay="10" direction="up" onmouseout="this.scrollAmount=2" onmouseover="this.scrollAmount=0">
                    <?php
                    $rsPartner = getPartnerClient(5);
                    while ($row = $db->fetch_array($rsPartner)) {
                        ?>
                    <div style="margin-bottom: 2px;">
                        <a href="<?php echo $row['link'];?>"><img alt="" src="<?php echo $row['filename'];?>" width="188px;"/></a>
                    </div>
                        <?php }?>
                </marquee>
            </div>
        </div>
        <div class="folder-bottom00">
            <div class="square-bottom00"></div>
        </div>
    </div>
    <?php  $rsAdv = getAdvClient('home', 'left', 5);
    if($db->num_rows($rsAdv)>0) {
        ?>
    <div class="folder" >
        <div class="folder-title-new00" >
            <div class="square00"></div>
            <div style="float: left;color: #000">[Quảng cáo]</div>
        </div>
        <div class="folder-body00" >
                <?php
                while ($row = $db->fetch_array($rsAdv)) {
                    ?>
            <div style="margin-bottom: 2px;">
                <a href="<?php echo $row['link'];?>"><img alt="" src="<?php echo $row['filename'];?>" width="188px;"/></a>
            </div>
                    <?php }?>
        </div>
        <div class="folder-bottom00">
            <div class="square-bottom00"></div>
        </div>
    </div>
        <?php } ?>
</div>
</div>


